<?php

declare(strict_types=1);

namespace app\admin\controller\zadan;

use think\facade\Request;
use app\common\service\ZadanPlayerinfo as S;
use app\common\model\ZadanPlayerinfo as M;
use app\common\model\AdminAdmin as UM;

class Playerinfo extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(M::getList());
        }
        return $this->fetch();
    }
    // 查询用户名
    public function queryuname()
    {
        $data = UM::getqueryuname(Request::post('actorname'), Request::post('serverid'));

        $response = [
            'msg' => '操作成功',
            'code' => 200,
            'data' => $data,
        ];
        return json($response);
    }

    // 发送金币
    public function sendCoin()
    {
        //查询用户是否发送过，发送过则不发送
        $playerInfo = M::playerInfo(Request::post('actorid'), Request::post('account'), Request::post('qufu'))[0];

        if ($playerInfo["isdefaultcoin"] == 2) {
            $response = [
                'msg' => '玩家已接收过赠送的超级金币！',
                'code' => 200,
                'data' => '',
            ];
            return json($response);
        } else {
            //查询配置，发送金币数量
            $configInfo = M::configInfo();
            $response = [
                'msg' => '操作成功',
                'code' => 200,
                'data' => M::sendCoin(Request::post('actorid'), Request::post('account'), Request::post('qufu'), $configInfo["sendcoinlimit"], $playerInfo["cjcoin"]),
            ];
            return json($response);
        }
    }

    // 发送金币 多个发送
    public function onekeysend()
    {
        return json(S::onekeysend(Request::post('ids')));
    }

    // 测试榜单排名奖励发送
    public function sendBroad()
    {
        if (Request::post('type') == "all") {
            $response = [
                'msg' => '操作成功',
                'code' => 200,
                'data' => M::sendRewardAll(),
            ];
            return json($response);
        }
        if (Request::post('type') == "day") {
            $response = [
                'msg' => '操作成功',
                'code' => 200,
                'data' => M::sendRewardDay(),
            ];
            return json($response);
        }
    }

    // 一键清理限制 金币发放限制
    public function onekeyCoinLimit()
    {
        if (Request::post('serverid')) {
            $response = [
                'msg' => '操作成功',
                'code' => 200,
                'data' => M::onekeyCoinLimit(Request::post('serverid')),
            ];
            return json($response);
        } else {
            $response = [
                'msg' => '操作成功',
                'code' => 200,
                'data' => M::onekeyCoinLimitNoServerid(),
            ];
            return json($response);
        }
    }

    // 清理单个玩家限制  金币发放限制
    public function onePlayerCoinLimit()
    {
        $response = [
            'msg' => '操作成功',
            'code' => 200,
            'data' => M::onePlayerCoinLimit(Request::post('actorid'), Request::post('actorname'), Request::post('serverid')),
        ];
        return json($response);
    }



    // 配置
    public function config()
    {
        if (Request::isPost()) {
            $activiteisopen = Request::post('activiteisopen');
            $desc = Request::post('desc');
            $typels = Request::post('typels');
            $dhbl = Request::post('dhbl');
            $daysendgoodsls = Request::post('daysendgoodsls');
            $allsendgoodsls = Request::post('allsendgoodsls');
            $sendcoinlimit = Request::post('sendcoinlimit');
            $onenumcoin = Request::post('onenumcoin');
            $rankdaynum = Request::post('rankdaynum');
            $rankallnum = Request::post('rankallnum');

            M::configMo($activiteisopen, $desc, $typels, $dhbl, $daysendgoodsls, $allsendgoodsls, $sendcoinlimit, $onenumcoin, $rankdaynum, $rankallnum);


            return  $this->success('保存成功', Request::root() . '/blackbox.playerinfo/config');
        }
        $data = M::configInfo();

        $ItemLs = UM::getItemLsSelect();
        $ItemLs1 = $ItemLs;
        return $this->fetch('', ['data' => $data, 'ItemLs' => $ItemLs, 'ItemLs1' => $ItemLs1, 'ServerLs' => UM::getServerLsSelect()]);
    }

    // 添加
    public function add()
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goAdd(Request::post()));
        }
        return $this->fetch();
    }

    // 编辑
    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goEdit(Request::post(), $id));
        }
        return $this->fetch('', ['model' => M::find($id)]);
    }

    // 状态
    public function status($id)
    {
        return $this->getJson(S::goStatus(Request::post('status'), $id));
    }

    // 删除
    public function remove($id)
    {
        return $this->getJson(S::goRemove($id));
    }

    // 批量删除
    public function batchRemove()
    {
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
    }

    // 回收站
    public function recycle()
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goRecycle());
        }
        return $this->fetch();
    }
}
